﻿@model BlogPostModel

@using SmartStore.Core.Domain.Blogs;
@using Telerik.Web.Mvc.UI;

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

@Html.SmartStore().TabStrip().Name("blog-post-edit").Style(TabsStyle.Material).Items(x =>
{   
    x.Add().Text(T("Admin.ContentManagement.Blog.BlogPosts.Info").Text)
        .Content(TabInfo())
        .Selected(true);

    x.Add().Text(T("Admin.Common.SEO").Text)
        .Content(TabSeo());

    EngineContext.Current.Resolve<IEventPublisher>().Publish(new TabStripCreated(x, "blog-post-edit", this.Html, this.Model));
})

@helper TabInfo()
{
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Title)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.Title)
                @Html.ValidationMessageFor(model => model.Title)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Intro)
            </td>
            <td class="adminData wide">
                @Html.TextAreaFor(model => model.Intro, new { style = "height:100px" })
                @Html.ValidationMessageFor(model => model.Intro)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Body)
            </td>
            <td class="adminData wide">
                @Html.EditorFor(x => x.Body, "Html")
                @Html.ValidationMessageFor(model => model.Body)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.Tags)
            </td>
            <td class="adminData">
                @Html.ListBoxFor(model => model.Tags, Model.AvailableTags, new { multiple = "multiple", data_tags = "true" })
                @Html.ValidationMessageFor(model => model.Tags)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div class="admin-config-group">
                    <div class="head">@T("Admin.ContentManagement.Blog.Heading.Publish")</div>
                </div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.IsPublished)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.IsPublished)
                @Html.ValidationMessageFor(model => model.IsPublished)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.LanguageId)
            </td>
            <td class="adminData">
                @Html.DropDownListFor(model => model.LanguageId, new SelectList(ViewBag.AllLanguages, "Id", "Name"))
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.SelectedStoreIds)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.SelectedStoreIds)
                @Html.ValidationMessageFor(model => model.SelectedStoreIds)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.StartDate)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.StartDate)
                @Html.ValidationMessageFor(model => model.StartDate)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.EndDate)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.EndDate)
                @Html.ValidationMessageFor(model => model.EndDate)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.CreatedOnUtc)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.CreatedOnUtc)
                @Html.ValidationMessageFor(model => model.CreatedOnUtc)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div class="admin-config-group">
                    <div class="head">@T("Admin.ContentManagement.Blog.Heading.Display")</div>
                </div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.PreviewDisplayType)
            </td>
            <td class="adminData">
                @Html.DropDownListForEnum(model => model.PreviewDisplayType)
                @Html.ValidationMessageFor(model => model.PreviewDisplayType)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.PictureId)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.PictureId, new { transientUpload = true })
                @Html.ValidationMessageFor(model => model.PictureId)
            </td>
        </tr>
        <tr id="pnlPreviewPicture">
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.PreviewPictureId)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.PreviewPictureId, new { transientUpload = true })
                @Html.ValidationMessageFor(model => model.PreviewPictureId)
            </td>
        </tr>
        <tr id="pnlSectionBg">
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.SectionBg)
            </td>
            <td class="adminData">
                @{ 
                    var brandColors = GetThemeVariable("brand-colors")
                        .Trim()
                        .SplitSafe(",")
                        .Select(x => x.TrimSafe())
                        .Select(x => new SelectListItem { Text = x, Value = x })
                        .ToList();
                }

                @Html.DropDownListFor(model => model.SectionBg, brandColors, T("Common.Unspecified"))
                @Html.ValidationMessageFor(model => model.SectionBg)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.AllowComments)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AllowComments)
                @Html.ValidationMessageFor(model => model.AllowComments)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.DisplayTagsInPreview)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.DisplayTagsInPreview)
                @Html.ValidationMessageFor(model => model.DisplayTagsInPreview)
            </td>
        </tr>

    </table>
}
@helper TabSeo()
{
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.MetaKeywords)
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaKeywords)
                @Html.ValidationMessageFor(model => model.MetaKeywords)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.MetaDescription)
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaDescription)
                @Html.ValidationMessageFor(model => model.MetaDescription)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.MetaTitle)
            </td>
            <td class="adminData">
                @Html.EditorFor(x => x.MetaTitle)
                @Html.ValidationMessageFor(model => model.MetaTitle)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.SmartLabelFor(model => model.SeName)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.SeName)
                @if (Model.Id != 0)
                {
                    @Html.Action("NamesPerEntity", "UrlRecord", new { entityName = "BlogPost", entityId = Model.Id })
                }
                @Html.ValidationMessageFor(model => model.SeName)
            </td>
        </tr>
    </table>
}

<script>
    $(function () {
        $('#@Html.FieldIdFor(model => model.PreviewDisplayType)').change(function () {
            $('#pnlPreviewPicture').toggle($(this).val() === '@(PreviewDisplayType.Preview.ToString())' || $(this).val() === '@(PreviewDisplayType.PreviewSectionBg.ToString())');
            $('#pnlSectionBg').toggle(
                $(this).val() === '@(PreviewDisplayType.DefaultSectionBg.ToString())' ||
                $(this).val() === '@(PreviewDisplayType.PreviewSectionBg.ToString())' ||
                $(this).val() === '@(PreviewDisplayType.SectionBg.ToString())'
            );
        }).trigger('change');
    });
</script>